package com.example.finalthesis.the_db4o_project;

/**
 * Created by ILIAS on 16/4/2015.
 */
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.finalthesis.the_db4o_project.ListOFObjects.ItemOfObject;

import java.util.List;

public class ItemAdapter extends ArrayAdapter<ItemOfObject> {

    private List<ItemOfObject> itemList;
    private Context ctx;

    public ItemAdapter(List<ItemOfObject> itemList, Context ctx) {
        super(ctx,R.layout.item, itemList);
        this.ctx = ctx;
        this.itemList = itemList;
    }

    @Override
    public int getCount() {
        return itemList.size();
    }

    @Override
    public ItemOfObject getItem(int position) {
        return itemList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return itemList.get(position).hashCode();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;

        if ( v == null) {
            LayoutInflater inf = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = (View) inf.inflate(R.layout.item , null);
            TextView tName = (TextView) v.findViewById(R.id.objectNameL);
            tName.setText(itemList.get(position).ObjectName);
        }

        return v;
    }
}
